package com.ddwl.order.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.order.service.OrderAddressServer;
import com.ddwl.order.service.OrderInfoServer;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.order.OrderRemarkUpdaeBo;
import com.ddwl.schema.bo.order.QueryOrderListBo;
import com.ddwl.schema.bo.order.ShopConfirmOrderBo;
import com.ddwl.schema.bo.order.ShopDeliveryBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.order.OrderAddrVo;
import com.ddwl.schema.vo.order.OrderDetailVo;
import com.ddwl.schema.vo.order.OrderInfoListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 类ShopOrderController.java的实现描述：TODO
 *
 * @author zach
 * @Date :2020-12-03 19:41.
 */
@Api(tags = "店铺商家后台操作订单")
@RestController
@RequestMapping("/shop")
public class ShopOrderController extends BaseController {


    @Resource
    private OrderInfoServer orderInfoServer;
    @Resource
    private OrderAddressServer orderAddressServer;

    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("商家后台查询订单列表")
    public RestVo<PageVo<OrderInfoListVo>> shopPage(@Valid @RequestBody PageBo<QueryOrderListBo> pageBo) {
        if (pageBo.getParam() == null) {
            pageBo.setParam(new QueryOrderListBo());
        }
        //默认查询当前登录用户店铺信息
        pageBo.getParam().setShopId(getShopId());
        return RestVo.ok(orderInfoServer.getPage(pageBo));
    }

    @GetMapping("/detail")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("商户后台查看订单详情")
    public RestVo<OrderDetailVo> shopDetail(@RequestParam String id) {
        return RestVo.ok(orderInfoServer.getShopOrderDetail(getShopId(), id));
    }

    @PostMapping("/update/remark")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("商家修改订单备注")
    public RestVo updateRemark(@Valid @RequestBody OrderRemarkUpdaeBo updaeBo) {
        updaeBo.setShopId(getShopId());
        orderInfoServer.shopUpdateOrderRemark(updaeBo);
        return RestVo.ok();
    }


    @PostMapping("/shopConfirmOrder")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("商家核销自提订单")
    public RestVo shopConfirmOrder(@Valid @RequestBody ShopConfirmOrderBo confirmOrderBo) {
        confirmOrderBo.setShopId(getShopId());
        orderInfoServer.shopConfirmOrder(confirmOrderBo);
        return RestVo.ok();
    }

    @PostMapping("/shopDelivery")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("商家整单发货接口")
    public RestVo shopDelivery(@Valid @RequestBody ShopDeliveryBo deliveryBo) {
        deliveryBo.setShopId(getShopId());
        orderInfoServer.shopDelivery(deliveryBo);
        return RestVo.ok();
    }

    @GetMapping("/getOrderAddr")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("商家查询订单收货信息")
    public RestVo<OrderAddrVo> getOrderAddr(@RequestParam(name = "orderId") String orderId) {
        return RestVo.ok(orderAddressServer.getShopOrderAddr(orderId, getShopId()));
    }

}
